package com.dfbz.demo02_lambda表达式语法;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {

    public static void main(String[] args) {

//        Task t1=new DownloadTask();

        /*Task t2=new Task() {
            @Override
            public void run() {
                System.out.println("清理垃圾...");
            }
        };*/

        /*
        class Xxx implements Task{
            public void run(){
                System.out.println("聊天任务..")
            }
        }

        Task t3 = new Xxx();

         */
//        Task t3 = () -> System.out.println("聊天任务..");


        Handler handler = new Handler(() -> System.out.println("聊天任务...."));
        handler.doHandler();

    }

    public static void test(String[] args) {

        Task t1 = new DownloadTask();
        t1.run();
        System.out.println("----------------");


        // 匿名内部类
        Task t2 = new Task() {
            @Override
            public void run() {
                System.out.println("上传任务...");
            }
        };

        t2.run();
        System.out.println("-----------");

        Task t3 = () -> {
            System.out.println("聊天任务");
        };
        t3.run();
        System.out.println("------------");


        Task t4 = () -> System.out.println("清理垃圾...");
        t4.run();
    }
}

class Handler {
    private Task task;

    public void doHandler() {
        if (task != null) {
            task.run();
            return;
        }
        System.out.println("task还没有被赋值！");
    }

    public Handler() {
    }

    public Handler(Task task) {
        this.task = task;
    }
}

interface Task {
    void run();
}

class DownloadTask implements Task {

    @Override
    public void run() {
        System.out.println("下载任务...");
    }
}
